Cara Mendapatkan paypal API

Beberapa langkah untuk memulai:

  1. Mula-mula, pastinya kita harus bikin account paypal dulu yang akan dijadikan sebagai merchant (penerima duit). Untuk sandbox, bikinnya di http://developer.paypal.com (daftar beneran dulu untuk bisa bikin account bo’ongan/ tester account setelah login. daftarnya gratis kok).
  2. login pakai account tersebut (kalau pakai sandbox, login sandbox dulu baru login account tester)
  3. 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)
  4. Anda akan mendapatkan:
    • API Username
    • API Password
    • API Signature

Implementasi:

Tiga data diatas dimasukkan kedalam $ppConfig.

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',
09 'APISignature' => 'Au4SU-K4fYYF.P79qKJxkZVnRl99Aajgl6JLQDOqRPpDrqFGThC-rB4H',
10 'EndPointURL' => 'https://api-3t.sandbox.paypal.com/nvp'); // untuk yang bukan sandbox, alamatnya https://api-3t.paypal.com/nvp
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 );
19
20 $CCDetails = array(
21 'creditcardtype' => 'Visa',
22 'acct' => '4635800000835916',
23 'expdate' => '052012',
24 'cvv2' => '123',
25 'startdate' => ''
26 );
27
28 $PayerInfo = array(
29 'email' => 'tester@testerson.com',
30 'business' => 'Testers, LLC'
31 );
32
33 $PayerName = array(
34 'salutation' => 'Mr.',
35 'firstname' => 'Tester',
36 'middlename' => 'T.',
37 'lastname' => 'Testerson',
38 'suffix' => 'Jr.'
39 );
40
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'
49 );
50
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' => '',
73 'notifyurl' => ''
74 );
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();
93 ?>

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',
09 'APISignature' => 'Au4SU-K4fYYF.P79qKJxkZVnRl99Aajgl6JLQDOqRPpDrqFGThC-rB4H',
10 'EndPointURL' => 'https://api-3t.sandbox.paypal.com/nvp'); // untuk yang bukan sandbox, alamatnya https://api-3t.paypal.com/nvp
11
12 $pp = new PayPal($ppConfig);
13
14 # Populate data arrays for API call.
15 $SECFields = array(
16 'returnurl' => 'http://www.domain.com/return.php',
17 'cancelurl' => 'http://www.domain.com/cancel.php',
18 'paymentaction' => 'Sale'
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 ?>

paypal.nvp.clssass download here

Butuh coba-coba sendiri sambil lirik classnya kalau mau buat bayar multiple items. ;)

Sekedar pengingat. Jangan lupa beli hosting dengan dedicated IP dan install SSL.

Terlihat mudah bukan?

source: rumahdot