Beberapa langkah untuk memulai:
- Mula-mula, pastinya kita harus buat account paypal yang akan dijadikan sebagai merchant (penerima uang). Untuk sandbox, buat di http://developer.paypal.com (daftar dulu untuk bisa bikintester account setelah login.
- login pakai account tersebut (kalau pakai sandbox, login sandbox dan selanjutnya login account tester)
- My Account > Profile > Get API Credentials . Ikuti petunjuknya untuk mendapatkan PayPal API Signature untuk Website Payment Pro (bukan Payflow Pro) dengan integrasi sendiri (bukan pakai third-party shopping cart)
- Anda akan mendapatkan:
- API Username
- API Password
- API Signature
Implementasi:
Tiga data diatas dimasukkan kedalam $appConfig.
01 | <?php |
02 | # Add PayPal class |
03 | require_once(‘../PayPalApps/paypal.nvp.class.php’); |
04 | |
05 | # Setup the PayPal object |
06 | $ppConfig = array(‘Sandbox’ => true, //set false untuk non-sandbox |
07 | ‘APIUsername’ => ‘jbuzz547_api1.ymail.com’, |
08 | ‘APIPassword’ => ‘AW9KUMJRLYG5XSX3′, |
11 | $pp = new PayPal($ppConfig); |
12 | |
13 | # Populate data arrays for API call. |
14 | $DPFields = array( |
15 | ‘paymentaction’ => ‘Sale’, |
16 | ‘ipaddress’ => ‘192.168.1.34’, |
17 | ‘returnfmfdetails’ => ‘1’ |
18 | ); |
21 | ‘creditcardtype’ => ‘Visa’, |
22 | ‘acct’ => ‘4635800000835916’, |
23 | ‘expdate’ => ‘052012’, |
24 | ‘cvv2′ => ‘123’, |
29 | ‘email’ => ‘tester@testerson.com’, |
30 | ‘business’ => ‘Testers, LLC’ |
33 | $PayerName = array( |
34 | ‘salutation’ => ‘Mr.’, |
35 | ‘firstname’ => ‘Tester’, |
36 | ‘middlename’ => ‘T.’, |
37 | ‘lastname’ => ‘Testerson’, |
38 | ‘suffix’ => ‘Jr.’ |
41 | $BillingAddress = array( |
42 | ‘street’ => ‘123 Test Ave.’, |
43 | ‘street2′ => ‘Apt. 3′, |
44 | ‘city’ => ‘Testersville’, |
45 | ‘state’ => ‘MO’, |
46 | ‘countrycode’ => ‘US’, |
47 | ‘zip’ => ‘64030’, |
48 | ‘phonenum’ => ‘555-555-5555′ |
51 | $ShippingAddress = array( |
52 | ‘shiptoname’ => ‘Mr. Tester Testerson Jr.’, |
53 | ‘shiptostreet’ => ‘123 Test Ave’, |
54 | ‘shiptostreet2′ => ‘Apt. 3′, |
55 | ‘shiptocity’ => ‘Testersville’, |
56 | ‘shiptostate’ => ‘MO’, |
57 | ‘shiptozip’ => ‘64030’, |
58 | ‘shiptocountrycode’ => ‘US’, |
59 | ‘shiptophonenum’ => ‘555-555-5555′ |
60 | ); |
61 | |
62 | $PaymentDetails = array( |
63 | ‘amt’ => ‘25.00’, |
64 | ‘currencycode’ => ‘USD’, |
65 | ‘itemamt’ => ‘15.00’, |
66 | ‘shippingamt’ => ‘10.00’, |
67 | ‘handlingamt’ => ”, |
68 | ‘taxamt’ => ”, |
69 | ‘desc’ => ‘This is a test order.’, |
70 | ‘custom’ => ”, |
71 | ‘invnum’ => ‘1234-ABC’, |
72 | ‘buttonsource’ => ”, |
75 | |
76 | # Now combine your data arrays into a single nested array to pass into the class. |
77 | $DPData = array( |
78 | ‘DPFields’ => $DPFields, |
79 | ‘CCDetails’ => $CCDetails, |
80 | ‘PayerInfo’ => $PayerInfo, |
81 | ‘PayerName’ => $PayerName, |
82 | ‘BillingAddress’ => $BillingAddress, |
83 | ‘ShippingAddress’ => $ShippingAddress, |
84 | ‘PaymentDetails’ => $PaymentDetails); |
85 | |
86 | # Now we pass the nested array of all our data into the class. |
87 | $DPResult = $pp -> DoDirectPayment($DPData); |
88 | |
89 | # Now lets study the result array |
90 | echo ‘<pre />'; |
91 | print_r($DPResult); |
92 | exit(); |
Kalau yang ini untuk pembayaran dengan account PayPal :
01 | <?php |
02 | # Add PayPal class |
03 | require_once(‘../PayPalApps/paypal.nvp.class.php’); |
04 | |
05 | # Setup the PayPal object |
06 | $ppConfig = array(‘Sandbox’ => true, // set false untuk non-sandbox |
07 | ‘APIUsername’ => ‘jbuzz547_api1.ymail.com’, |
08 | ‘APIPassword’ => ‘AW9KUMJRLYG5XSX3′, |
11 | |
12 | $pp = new PayPal($ppConfig); |
13 | |
14 | # Populate data arrays for API call. |
19 | ); |
20 | $PaymentDetails = array( |
21 | ‘amt’ => ‘18.00’, |
22 | ‘currencycode’ => ‘USD’, |
23 | ‘itemamt’ => ‘10.00’, |
24 | ‘shippingamt’ => ‘5.00’, |
25 | ‘handlingamt’ => ‘2.00’, |
26 | ‘taxamt’ => ‘1.00’, |
27 | ‘desc’ => ‘This is a test order.’, |
28 | ‘custom’ => ”, |
29 | ‘invnum’ => ‘1234-ABC’ |
30 | ); |
31 | |
32 | # Now combine your data arrays into a single nested array to pass into the class. |
33 | $SECData = array( |
34 | ‘SECFields’ => $SECFields, |
35 | ‘PaymentDetails’ => $PaymentDetails |
36 | ); |
37 | |
38 | # Now we pass the nested array of all our data into the class. |
39 | $SECResult = $pp -> SetExpressCheckout($SECData); |
40 | |
41 | # Now lets study the result array |
42 | echo ‘<pre />'; |
43 | print_r($SECResult); |
44 | exit(); |
45 | |
46 | # Now we can just use the returned REDIRECTURL field to redirect the user to PayPal based on our input. |
47 | header(‘Location: ‘ . $SECResult[‘REDIRECTURL’]); |
48 | ?> |
|